/*
    SUSAN® - Sole of Unix Save ANything

   Copyright (C) 2011-2011 Hechzh Property
   Copyright (C) 2016-2016 Skyatlas Co. CN
   

   
*/
#ifndef BAREOS_CATS_BDB_PRIV_H_
#define BAREOS_CATS_BDB_PRIV_H_ 1

#ifndef _BDB_PRIV_INTERFACE_
#error "Illegal inclusion of catalog private interface"
#endif

struct AttributesDbRecord;
class JobControlRecord;

class BareosDbPrivateInterface : public BareosDb {
 protected:
  /*
   * Members
   */
  int status_ = 0;              /**< Status */
  int num_fields_ = 0;          /**< Number of fields returned by last query */
  int rows_size_ = 0;           /**< Size of malloced rows */
  int fields_size_ = 0;         /**< Size of malloced fields */
  int row_number_ = 0;          /**< Row number from xx_data_seek */
  int field_number_ = 0;        /**< Field number from SqlFieldSeek */
  SQL_ROW rows_ = nullptr;      /**< Defined rows */
  SQL_FIELD* fields_ = nullptr; /**< Defined fields */
  bool allow_transactions_ = false; /**< Transactions allowed ? */
  bool transaction_ = false;        /**< Transaction started ? */

 private:
  /*
   * Methods
   */
  void SqlFieldSeek(int field) override { field_number_ = field; }
  int SqlNumFields(void) override { return num_fields_; }
  virtual void SqlFreeResult(void) override = 0;
  virtual SQL_ROW SqlFetchRow(void) override = 0;
  virtual bool SqlQueryWithHandler(const char* query,
                                   DB_RESULT_HANDLER* ResultHandler,
                                   void* ctx) override = 0;
  virtual bool SqlQueryWithoutHandler(const char* query,
                                      int flags = 0) override = 0;
  virtual const char* sql_strerror(void) override = 0;
  virtual void SqlDataSeek(int row) override = 0;
  virtual int SqlAffectedRows(void) override = 0;
  virtual uint64_t SqlInsertAutokeyRecord(const char* query,
                                          const char* table_name) override = 0;
  virtual SQL_FIELD* SqlFetchField(void) override = 0;
  virtual bool SqlFieldIsNotNull(int field_type) override = 0;
  virtual bool SqlFieldIsNumeric(int field_type) override = 0;
  virtual bool SqlBatchStartFileTable(JobControlRecord* jcr) override = 0;
  virtual bool SqlBatchEndFileTable(JobControlRecord* jcr,
                                    const char* error) override = 0;
  virtual bool SqlBatchInsertFileTable(JobControlRecord* jcr,
                                       AttributesDbRecord* ar) override = 0;

 public:
  BareosDbPrivateInterface() = default;
  virtual ~BareosDbPrivateInterface() = default;
};
#endif /* BAREOS_CATS_BDB_PRIV_H_ */
